package com.icode.web.socket.standard;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

/**
 * User: alexz
 * Date: 14-7-31
 * Time: 下午5:20
 */
//@ServerEndpoint("/chat")
public class ChatEndpoint {
    private Session session;

    @OnOpen
    public void open(Session session) {
        this.session = session;
    }

    @OnClose
    public void close() {

    }

    @OnMessage
    public void receive(String message) throws IOException {
        RemoteEndpoint.Basic basicRemote = session.getBasicRemote();
        basicRemote.sendText(message);
    }

    @OnError
    public void error(Throwable t) throws Throwable {
    }
}
